<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>公告列表</title>
<script language="javascript" src="/js/js.js"></script>

<link href="/styles/style.css" rel="stylesheet" type="text/css">
<STYLE type=text/css>
#demo a div {
	height: 20px;
	color: #FF0000;
}

#demo a {
	width: 100%;
	overflow: hidden;
	font: 12px/16px tahoma;
	display: block;
	text-decoration: none;
	margin: 2px;
	color: #4a551c;
	padding-left: 2px;
	text-align: left;
}
</STYLE>
<script type="text/javascript" src="/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
	$(function() {

		$.post("/admin/ajaxannolist", function(data) {

			var html = "";
			for (var i = 0; i < data.length; i++) {

				html += "<a href='#'><div>";
				html += "<font style='font-weight: bold;'> >>>&nbsp;&nbsp; "
						+ data[i].department
						+ "</font>&nbsp;&nbsp;&nbsp;&nbsp;"
				html += data[i].astart + "&nbsp;&nbsp;&nbsp;&nbsp;发表公告："
						+ data[i].acomment + "!"
				html += "</div></a>"
			}

			$("#demo1").html("");
			$("#demo1").append(html);

		}, "json");
	});
	function valipub() {

		var val = confirm("确认发布么？");
		if (val == false) {

			return false;
		}
		return true;
	}
	function valicancel() {

		var val = confirm("确认撤销么？");
		if (val == false) {

			return false;
		}
		return true;
	}

	function annofor(mes) {

		var c = mes.value;
		$
				.post(
						"/admin/ajax",
						{
							current : c
						},
						function(data) {

							//alert(data.list.length);
							$("#current").html(data.current);
							var html = "";
							for (var i = 0; i < data.list.length; i++) {

								html += "<tr>";
								html += "<td>" + data.list[i].department
										+ "</td>";
								html += "<td>" + data.list[i].acomment
										+ "</td>";
								html += "<td>" + data.list[i].astart + "</td>";
								html += "<td>" + data.list[i].aend + "</td>";
								if (data.list[i].astate == '1') {
									html += "<td><font color='green'>已发布</font></td>";
									html += "<td><a href='/admin/announcepub?astate=2&aid="
											+ data.list[i].aid
											+ "' onclick='return valicancel();'>撤销</a></td>"
								}
								if (data.list[i].astate == '2') {
									html += "<td><font color='green'>已撤销</font></td>";
									html += "<td></td>";
								}
								if (data.list[i].astate == '0') {
									html += "<td><font color='black'>未发布</font></td>";
									html += "<td><a href='/admin/initedit?aid="
											+ data.list[i].aid
											+ "' onclick=''>修改</a>&nbsp;&nbsp;<a href='/admin/announcepub?astate=1&aid="
											+ data.list[i].aid
											+ "' onclick='return valipub();'>发布</a></td>"
								}

								html += "</tr>";
							}
							$("#page").html("");
							$("#page").append(html);
						}, "json");
	}

	function writeAnno() {

		window.location.href = "/admin/announceadd";
	}
</script>
</head>
<body>
	<div class="topbtStyle">
		<input name="pizhun" type="button" onclick="writeAnno();"
			value="写 新 公 告" class="btn2" onmouseover="changebg(this,'2')"
			onmouseout="changebg(this,'2')" />
	</div>
	<hr />
	<table class="table11" style="width: 90%;">
		<tr>
			<th style="text-align: center;">最近一周的公告</th>
		</tr>

		<tr>
			<td><marquee direction="up" height="100%" scrollamount="2"
					onmousemove="this.stop()" onmouseout="this.start()">
					<div id="demo"
						style="overflow: hidden; height: 120px; border: 0px solid #dde5bc;">
						<div id="demo1"></div>
						<div id="demo2"></div>
					</div>
				</marquee></td>
		</tr>
	</table>
	<br />
	<br />
	<form method="post" name="myform" id="myform">
		<table class="table11" style="width: 90%;">
			<thead>
				<tr>
					<th>公告发布部门</th>
					<th style="width: 500px;">公告内容</th>
					<th style="text-align: center;">发布时间</th>
					<th style="text-align: center;">截止时间</th>
					<th style="text-align: center;">状态</th>
					<th style="text-align: center;">操作</th>
				</tr>
			</thead>
			<tbody id="page">
				<c:forEach items="${page.list }" var="item">
					<tr>
						<td>${item.department }</td>
						<td>${item.acomment }</td>
						<td>${item.astart }</td>
						<td>${item.aend }</td>
						<td><c:choose>

								<c:when test="${item.astate=='2'}">
									<font color="red">已撤销</font>
								</c:when>
								<c:when test="${item.astate=='1'}">
									<font color="green">已发布</font>
								</c:when>

								<c:when test="${item.astate=='0'}">
									<font color="black">未发布</font>
								</c:when>
							</c:choose></td>
						<td><c:choose>

								<c:when test="${item.astate=='1'}">
									<a href="/admin/announcepub?astate=2&aid=${item.aid }"
										onclick="return valicancel();">撤销</a>
								</c:when>

								<c:when test="${item.astate=='0'}">
									<a href="/admin/initedit?aid=${item.aid }">修改</a>&nbsp;&nbsp;<a
										href="/admin/announcepub?astate=1&aid=${item.aid }"
										onclick=" return valipub();">发布</a>
								</c:when>
							</c:choose></td>
					</tr>
				</c:forEach>
			</tbody>
		</table>
		<div>
			总共有<span class="red">${page.count }</span>条记录，总共有<span class="red">${page.total }</span>页，当前第<span
				class="red" id="current">${page.current }</span>页。 <a id="First"
				href="/admin/announcelist?current=1">首页</a> <a id="Prev"
				href="/admin/announcelist?current=${page.current - 1 }">上一页</a> <a
				id="Next"
				href="/admin/announcelist?current=${page.current +1<=page.total?page.current +1:page.total}">下一页</a>
			<a id="Last" href="/admin/announcelist?current=${page.total }">尾页</a>
			转到第 <select name="GoTo" id="GoTo" onchange="annofor(this);">
				<c:forEach begin="1" end="${page.total }" step="1" var="index">
					<option value="${index }">${index }</option>
				</c:forEach>
			</select> 页
		</div>
	</form>
</body>
</html>